<template>
  <div class="container">
    <RouterView></RouterView>
  </div>
</template>
<script lang='ts' setup>
import { useRouter } from 'vue-router';
import routeInfo from '@/components';
const router = useRouter();
//获取localStorage存储的menu信息
let menu = localStorage.getItem('menu');

if (menu) {
  const list: any = JSON.parse(menu);
  if (list.length) {
    let defaultMenu = list[0];
    //设置默认的展示页面
    router.addRoute('main', {
      path: '',
      name: 'default',
      component: routeInfo[defaultMenu['component']]
    })
    // 设置所有的路由信息
    list.forEach((item: any) => {
      router.addRoute('main', {
        path: item.path,
        name: item.name,
        component: routeInfo[item['component']]
      })
    })
  }
  // 获取当前url的路径
  let herf = location.pathname
  //将页面跳转至url指定的组件页面
  router.push(herf)
}
console.log(router.getRoutes());
</script>
<style lang="less" scoped>
.container {
  min-width: 1024px;
}
</style>